//
//  DetailTableViewController.m
//  吃货·上海
//
//  Created by lanou on 15/11/27.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "DessertDetailTableViewController.h"
#import "PrefixHeader.pch"
#import "UIImageView+WebCache.h"
#import "BgView.h"
#import "DessertDetailTableViewCell.h"
#import <ShareSDK/ShareSDK.h>

@interface DessertDetailTableViewController ()
//@property(nonatomic,strong)BgView *bgView;//封面视图
//@property(nonatomic,strong)UIImageView *pic;
//@property(nonatomic,strong)UIImageView *avatar;
//@property(nonatomic,strong)UILabel *nameLable;
//@property(nonatomic,strong)UILabel *menuNameLable;
//@property(nonatomic,strong)UILabel *detail;
@end

@implementation DessertDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc]initWithTitle:@"美食详情" style:UIBarButtonItemStylePlain target:self action:@selector(leftBtn:)];
    self.navigationItem.leftBarButtonItem = leftBtn;
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"share1"] style:UIBarButtonItemStylePlain target:self action:@selector(shareBtn:)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    
}



#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseIdentifier = @"cell";
    [tableView registerClass:[DessertDetailTableViewCell class] forCellReuseIdentifier:reuseIdentifier];
    DessertDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.model = self.model;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return [DessertDetailTableViewCell heightForCell:self.model];
}

- (void)leftBtn:(UIBarButtonItem *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)shareBtn:(UIBarButtonItem *)btn
{
    //NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"girl" ofType:@"png"];
    
//    构造分享的内容
    id<ISSContent> publishContent = [ShareSDK content:self.model.username defaultContent:self.model.msg image:[ShareSDK imageWithUrl:self.model.path] title:@"shareSDK" url:self.model.path description:self.model.msg mediaType:SSPublishContentMediaTypeNews];
    id<ISSContainer> container = [ShareSDK container];
    
//    IPad需要写下面这行
//    [container setIPadContainerWithView:self.model.path arrowDirect:UIPopoverArrowDirectionUp];
    
    [ShareSDK showShareActionSheet:container shareList:nil content:publishContent statusBarTips:YES authOptions:nil shareOptions:nil result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
        if (state == SSResponseStateSuccess) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"分享成功" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }
        else if (state == SSResponseStateFail)
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"分享失败" message:[NSString stringWithFormat:@"失败:%@",[error errorDescription]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }
    }];
    
    
    
}

@end
